#ifndef POSEESTIMATION_H
#define POSEESTIMATION_H
#include <QVector>
#include <QVector2D>
#include <QVector3D>
#include <QString>
#include <cv.hpp>
#include <QTextStream>
#include "Mesh.h"
class PoseEstimation
{
public:
    PoseEstimation();
    ~PoseEstimation();
    bool ReadImageFiducials(QString fileName);
    bool ReadMeshFiducials(QString fileName, QString meshFileName);

    void ComputePosePara();
    void SetLogTextStream(QTextStream* p);
    QString UpdateMeshColor(Mesh* pMesh, short imgIndex);
    void ComputeNearFrontalImgList();
    void MappingImagetoGeo(short imgIndex, QString geoImgFileName);
    void ConstructPixelMatrix(QVector<short> imgList, QString geoImgFileName);

    int GetUsedImgNum()
    {
        return imageNum;
    }
    int GetOriImgNum()
    {
        return oriImgNum;
    }
    QVector<short> GetFrontalImgListInUsedImgList()
    {
        return frontalImgListInUsedImgList;
    }

    QVector<short> GetFrontalImgIndexList();
    QVector<QString> GetFrontImgFileNameList();

    QVector<short> GetUsedImgList()
    {
        return usedImageList;
    }
    QVector<QString> GetUsedImgFileNameList()
    {
        return usedImgFileNameList;
    }
    QString GetImagesPath()
    {
        return imageFilePath;
    }
    cv::Mat GetPixelMatrix()
    {
        return pixelMatrix;
    }
    void IterNumAdd()
    {
        iterNum++;
    }

private:
    void ComputeCentroidImageFiducials();
    void ComputeCentroidMeshFiducials();
    void OutputMatrixToLog(cv::Mat cvMat, QString matName);//only support float type

private:

    QTextStream* logTextStream;

    int imageNum;
    int oriImgNum;
    short fiducialNum;
    QVector<QString> usedImgFileNameList;
    QVector<QVector2D> faceCenterList;
    QVector<float> faceBoxSizeList;//center to edge
    QVector<float> confidenceList;
    QVector<QVector2D> imageFiducialsList;//9 fiducials for each face
    QVector<QVector3D> meshFiducialsList;//only 1 mesh, so only 9 fiducials
    QVector<QVector2D> centroidImageFiducialsList;
    QVector3D centroidMeshFicucial;
    QVector<short> usedImageList;
    QVector<short> frontalImgListInUsedImgList;//find the image index in usedImageList, which are nearly frontal


    //q=scale * cvRotation * Q + cvTrans
    QVector<cv::Mat> cvRotation;
    QVector<cv::Mat> cvTrans;
    QVector<float> scales;
    QVector<QVector3D> rotAngle;
    QString imageFilePath;

    cv::Mat pixelMatrix;
    short iterNum;//记录迭代次数
};

#endif // POSEESTIMATION_H
